
# <> 提取参数
# <int:id> int 转换器

# 自定义转换器

from werkzeug.routing import BaseConverter
from flask import Flask

app = Flask(__name__)


class RegexConverter(BaseConverter):
    def __init__(self,url_map,regex):
        # 调用父类方法
        super(RegexConverter,self).__init__(url_map)
        self.regex = regex

    def to_python(self, value):
        # 父类的方法
        print('to_python被调用')
        return value

# 将自定义的转换器类添加到flask中
app.url_map.converters['re'] = RegexConverter

# {'re':RegexConverter}

@app.route('/index/<re("1\d{10}"):value>')
def index(value):
    print(value)
    return 'hello123'


if __name__ == '__main__':
    app.run()